package com.qf.first.service.impl;


import com.qf.first.dao.UserMapper;
import com.qf.first.entity.User;
import com.qf.first.pojo.bo.Code;
import com.qf.first.pojo.vo.UserRole;
import com.qf.first.pojo.bo.Code;
import com.qf.first.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpSession;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Transactional
    @Override
    public User checkUser(User user) {
        User user1 = userMapper.selectByUser(user);
        return user1;
    }

    @Override
    public int insertUser(User user) {
        int i = userMapper.insertUser(user);
        return i;
    }

    @Override
    public Boolean checkCode(String code, HttpSession session) {
        String serveCode = (String) session.getAttribute("serveCode");
        System.out.println(serveCode);
        if (!serveCode.equals(code)){
            return false;
        }
        return true;
    }

    @Override
    public UserRole getUser(User user) {
        UserRole userRole = userMapper.selectUserById(user);
        return userRole;
    }

    @Override
    public int updateUser(User user) {
        int i = userMapper.updateUser(user);
        return i;
    }

}
